
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/09/2011 23:29:36
-- Generated from EDMX file: C:\Users\nando\Documents\Visual Studio 2010\Projects\SGT\SGT\Datos\SGT_DB.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SGT_DB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Mercaderia]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sector] DROP CONSTRAINT [FK_Mercaderia];
GO
IF OBJECT_ID(N'[dbo].[FK_Proveedor]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Remito] DROP CONSTRAINT [FK_Proveedor];
GO
IF OBJECT_ID(N'[dbo].[FK_Sector]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Remito] DROP CONSTRAINT [FK_Sector];
GO
IF OBJECT_ID(N'[dbo].[fk_sector_pid]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sector] DROP CONSTRAINT [fk_sector_pid];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Configuraciones]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Configuraciones];
GO
IF OBJECT_ID(N'[dbo].[Deposito]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Deposito];
GO
IF OBJECT_ID(N'[dbo].[Mercaderia]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mercaderia];
GO
IF OBJECT_ID(N'[dbo].[Proveedor]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Proveedor];
GO
IF OBJECT_ID(N'[dbo].[Remito]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Remito];
GO
IF OBJECT_ID(N'[dbo].[Sector]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sector];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Deposito'
CREATE TABLE [dbo].[Deposito] (
    [DepositoID] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(100)  NULL,
    [Direccion] nvarchar(100)  NULL
);
GO

-- Creating table 'Mercaderia'
CREATE TABLE [dbo].[Mercaderia] (
    [MercaderiaID] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(100)  NOT NULL,
    [Densidad] float  NULL
);
GO

-- Creating table 'Proveedor'
CREATE TABLE [dbo].[Proveedor] (
    [ProveedorID] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(250)  NULL,
    [Direccion] nvarchar(250)  NULL,
    [Telefono] nvarchar(20)  NULL,
    [Contacto] nvarchar(100)  NULL
);
GO

-- Creating table 'Sector'
CREATE TABLE [dbo].[Sector] (
    [SectorID] int IDENTITY(1,1) NOT NULL,
    [Capacidad] float  NULL,
    [DepositoID] int  NULL,
    [MercaderiaID] int  NULL,
    [Nombre] nvarchar(20)  NULL,
    [UsoActual] float  NULL
);
GO

-- Creating table 'Configuraciones'
CREATE TABLE [dbo].[Configuraciones] (
    [ConfigID] int IDENTITY(1,1) NOT NULL,
    [Parametro] varchar(50)  NULL,
    [Valor] varchar(50)  NULL
);
GO

-- Creating table 'Remito'
CREATE TABLE [dbo].[Remito] (
    [RemitoID] int IDENTITY(1,1) NOT NULL,
    [Fecha] datetime  NOT NULL,
    [SectorID] int  NULL,
    [Referencia] nvarchar(50)  NULL,
    [ProveedorID] int  NOT NULL,
    [Peso] float  NOT NULL,
    [Notas] nvarchar(500)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [DepositoID] in table 'Deposito'
ALTER TABLE [dbo].[Deposito]
ADD CONSTRAINT [PK_Deposito]
    PRIMARY KEY CLUSTERED ([DepositoID] ASC);
GO

-- Creating primary key on [MercaderiaID] in table 'Mercaderia'
ALTER TABLE [dbo].[Mercaderia]
ADD CONSTRAINT [PK_Mercaderia]
    PRIMARY KEY CLUSTERED ([MercaderiaID] ASC);
GO

-- Creating primary key on [ProveedorID] in table 'Proveedor'
ALTER TABLE [dbo].[Proveedor]
ADD CONSTRAINT [PK_Proveedor]
    PRIMARY KEY CLUSTERED ([ProveedorID] ASC);
GO

-- Creating primary key on [SectorID] in table 'Sector'
ALTER TABLE [dbo].[Sector]
ADD CONSTRAINT [PK_Sector]
    PRIMARY KEY CLUSTERED ([SectorID] ASC);
GO

-- Creating primary key on [ConfigID] in table 'Configuraciones'
ALTER TABLE [dbo].[Configuraciones]
ADD CONSTRAINT [PK_Configuraciones]
    PRIMARY KEY CLUSTERED ([ConfigID] ASC);
GO

-- Creating primary key on [RemitoID] in table 'Remito'
ALTER TABLE [dbo].[Remito]
ADD CONSTRAINT [PK_Remito]
    PRIMARY KEY CLUSTERED ([RemitoID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [DepositoID] in table 'Sector'
ALTER TABLE [dbo].[Sector]
ADD CONSTRAINT [fk_sector_pid]
    FOREIGN KEY ([DepositoID])
    REFERENCES [dbo].[Deposito]
        ([DepositoID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'fk_sector_pid'
CREATE INDEX [IX_fk_sector_pid]
ON [dbo].[Sector]
    ([DepositoID]);
GO

-- Creating foreign key on [MercaderiaID] in table 'Sector'
ALTER TABLE [dbo].[Sector]
ADD CONSTRAINT [FK_Mercaderia]
    FOREIGN KEY ([MercaderiaID])
    REFERENCES [dbo].[Mercaderia]
        ([MercaderiaID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Mercaderia'
CREATE INDEX [IX_FK_Mercaderia]
ON [dbo].[Sector]
    ([MercaderiaID]);
GO

-- Creating foreign key on [ProveedorID] in table 'Remito'
ALTER TABLE [dbo].[Remito]
ADD CONSTRAINT [FK_Proveedor]
    FOREIGN KEY ([ProveedorID])
    REFERENCES [dbo].[Proveedor]
        ([ProveedorID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Proveedor'
CREATE INDEX [IX_FK_Proveedor]
ON [dbo].[Remito]
    ([ProveedorID]);
GO

-- Creating foreign key on [SectorID] in table 'Remito'
ALTER TABLE [dbo].[Remito]
ADD CONSTRAINT [FK_Sector]
    FOREIGN KEY ([SectorID])
    REFERENCES [dbo].[Sector]
        ([SectorID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Sector'
CREATE INDEX [IX_FK_Sector]
ON [dbo].[Remito]
    ([SectorID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------